package screenIntroduction;

import java.awt.Color;
import java.awt.DisplayMode;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import java.io.File;

import javax.imageio.ImageIO;
import javax.swing.JFrame;

@SuppressWarnings("serial")
public class Images extends JFrame {
    
    private Screen s;
    private BufferedImage bg; //background
    private BufferedImage pic; //picture
    private boolean loaded = false;
    
    public static void main(String[] args) {
	DisplayMode dm = new DisplayMode(800,600,16, DisplayMode.REFRESH_RATE_UNKNOWN);
	Images i = new Images();
	i.run(dm);
    }
    

    public void run (DisplayMode dm) {
	setBackground(Color.PINK);
	setForeground(Color.CYAN);
	setFont(new Font("Arial", Font.PLAIN, 24));
	
	loaded = false;
	loadPics();
	
	s = new Screen();
	try {
	    s.setFullScreen(dm,  this);
	    try {
		Thread.sleep(5000);
	    } catch (Exception ex) {
		ex.printStackTrace();
	    }
	} catch (Exception ex) {
	    ex.printStackTrace();
	} finally {
	    s.restoreScreen();
	}
    }
    
    public void loadPics() {
	try {
	    //bg = ImageIO.read(new File("C:\\Users\\Pyrobellum\\Downloads\\background.png"));
	    bg = ImageIO.read(new File("resources/background.png"));
	    pic = ImageIO.read(new File("resources/face.png"));
	    loaded = true;
	} catch (Exception e) {
	    // TODO Auto-generated catch block
	    e.printStackTrace();
	}
	repaint();
    }

    public void paint(Graphics g) {
	if (g instanceof Graphics2D) {
	    Graphics2D g2 = (Graphics2D)g;
	    g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
	}
	if (loaded) {
	    g.drawImage(bg,0,0,null);
	    g.drawImage(pic, 170, 180, null);
	}
	g.drawString("Glory to the emperor!", 200, 200);
    }
}
